package cc.prayol.permission.mapper.auth;

import static cc.prayol.permission.mapper.auth.UserDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import cc.prayol.permission.entity.auth.User;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface UserMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    BasicColumn[] selectList = BasicColumn.columnList(userId, deptId, loginName, userName, userType, email, phonenumber, sex, avatar, password, salt, status, deleted, loginIp, loginDate, createBy, createTime, updateBy, updateTime, remark);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<User> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("UserResult")
    Optional<User> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="UserResult", value = {
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="dept_id", property="deptId", jdbcType=JdbcType.BIGINT),
        @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_type", property="userType", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="phonenumber", property="phonenumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.CHAR),
        @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="salt", property="salt", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.CHAR),
        @Result(column="deleted", property="deleted", jdbcType=JdbcType.BIT),
        @Result(column="login_ip", property="loginIp", jdbcType=JdbcType.VARCHAR),
        @Result(column="login_date", property="loginDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_by", property="createBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_by", property="updateBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
    })
    List<User> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    default int deleteByPrimaryKey(Long userId_) {
        return delete(c -> 
            c.where(userId, isEqualTo(userId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    default int insert(User record) {
        return MyBatis3Utils.insert(this::insert, record, user, c ->
            c.map(userId).toProperty("userId")
            .map(deptId).toProperty("deptId")
            .map(loginName).toProperty("loginName")
            .map(userName).toProperty("userName")
            .map(userType).toProperty("userType")
            .map(email).toProperty("email")
            .map(phonenumber).toProperty("phonenumber")
            .map(sex).toProperty("sex")
            .map(avatar).toProperty("avatar")
            .map(password).toProperty("password")
            .map(salt).toProperty("salt")
            .map(status).toProperty("status")
            .map(deleted).toProperty("deleted")
            .map(loginIp).toProperty("loginIp")
            .map(loginDate).toProperty("loginDate")
            .map(createBy).toProperty("createBy")
            .map(createTime).toProperty("createTime")
            .map(updateBy).toProperty("updateBy")
            .map(updateTime).toProperty("updateTime")
            .map(remark).toProperty("remark")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.624+08:00", comments="Source Table: sys_user")
    default int insertSelective(User record) {
        return MyBatis3Utils.insert(this::insert, record, user, c ->
            c.map(userId).toPropertyWhenPresent("userId", record::getUserId)
            .map(deptId).toPropertyWhenPresent("deptId", record::getDeptId)
            .map(loginName).toPropertyWhenPresent("loginName", record::getLoginName)
            .map(userName).toPropertyWhenPresent("userName", record::getUserName)
            .map(userType).toPropertyWhenPresent("userType", record::getUserType)
            .map(email).toPropertyWhenPresent("email", record::getEmail)
            .map(phonenumber).toPropertyWhenPresent("phonenumber", record::getPhonenumber)
            .map(sex).toPropertyWhenPresent("sex", record::getSex)
            .map(avatar).toPropertyWhenPresent("avatar", record::getAvatar)
            .map(password).toPropertyWhenPresent("password", record::getPassword)
            .map(salt).toPropertyWhenPresent("salt", record::getSalt)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(deleted).toPropertyWhenPresent("deleted", record::getDeleted)
            .map(loginIp).toPropertyWhenPresent("loginIp", record::getLoginIp)
            .map(loginDate).toPropertyWhenPresent("loginDate", record::getLoginDate)
            .map(createBy).toPropertyWhenPresent("createBy", record::getCreateBy)
            .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
            .map(updateBy).toPropertyWhenPresent("updateBy", record::getUpdateBy)
            .map(updateTime).toPropertyWhenPresent("updateTime", record::getUpdateTime)
            .map(remark).toPropertyWhenPresent("remark", record::getRemark)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default Optional<User> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default List<User> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default List<User> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default Optional<User> selectByPrimaryKey(Long userId_) {
        return selectOne(c ->
            c.where(userId, isEqualTo(userId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, user, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    static UpdateDSL<UpdateModel> updateAllColumns(User record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(userId).equalTo(record::getUserId)
                .set(deptId).equalTo(record::getDeptId)
                .set(loginName).equalTo(record::getLoginName)
                .set(userName).equalTo(record::getUserName)
                .set(userType).equalTo(record::getUserType)
                .set(email).equalTo(record::getEmail)
                .set(phonenumber).equalTo(record::getPhonenumber)
                .set(sex).equalTo(record::getSex)
                .set(avatar).equalTo(record::getAvatar)
                .set(password).equalTo(record::getPassword)
                .set(salt).equalTo(record::getSalt)
                .set(status).equalTo(record::getStatus)
                .set(deleted).equalTo(record::getDeleted)
                .set(loginIp).equalTo(record::getLoginIp)
                .set(loginDate).equalTo(record::getLoginDate)
                .set(createBy).equalTo(record::getCreateBy)
                .set(createTime).equalTo(record::getCreateTime)
                .set(updateBy).equalTo(record::getUpdateBy)
                .set(updateTime).equalTo(record::getUpdateTime)
                .set(remark).equalTo(record::getRemark);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(User record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(userId).equalToWhenPresent(record::getUserId)
                .set(deptId).equalToWhenPresent(record::getDeptId)
                .set(loginName).equalToWhenPresent(record::getLoginName)
                .set(userName).equalToWhenPresent(record::getUserName)
                .set(userType).equalToWhenPresent(record::getUserType)
                .set(email).equalToWhenPresent(record::getEmail)
                .set(phonenumber).equalToWhenPresent(record::getPhonenumber)
                .set(sex).equalToWhenPresent(record::getSex)
                .set(avatar).equalToWhenPresent(record::getAvatar)
                .set(password).equalToWhenPresent(record::getPassword)
                .set(salt).equalToWhenPresent(record::getSalt)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(deleted).equalToWhenPresent(record::getDeleted)
                .set(loginIp).equalToWhenPresent(record::getLoginIp)
                .set(loginDate).equalToWhenPresent(record::getLoginDate)
                .set(createBy).equalToWhenPresent(record::getCreateBy)
                .set(createTime).equalToWhenPresent(record::getCreateTime)
                .set(updateBy).equalToWhenPresent(record::getUpdateBy)
                .set(updateTime).equalToWhenPresent(record::getUpdateTime)
                .set(remark).equalToWhenPresent(record::getRemark);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default int updateByPrimaryKey(User record) {
        return update(c ->
            c.set(deptId).equalTo(record::getDeptId)
            .set(loginName).equalTo(record::getLoginName)
            .set(userName).equalTo(record::getUserName)
            .set(userType).equalTo(record::getUserType)
            .set(email).equalTo(record::getEmail)
            .set(phonenumber).equalTo(record::getPhonenumber)
            .set(sex).equalTo(record::getSex)
            .set(avatar).equalTo(record::getAvatar)
            .set(password).equalTo(record::getPassword)
            .set(salt).equalTo(record::getSalt)
            .set(status).equalTo(record::getStatus)
            .set(deleted).equalTo(record::getDeleted)
            .set(loginIp).equalTo(record::getLoginIp)
            .set(loginDate).equalTo(record::getLoginDate)
            .set(createBy).equalTo(record::getCreateBy)
            .set(createTime).equalTo(record::getCreateTime)
            .set(updateBy).equalTo(record::getUpdateBy)
            .set(updateTime).equalTo(record::getUpdateTime)
            .set(remark).equalTo(record::getRemark)
            .where(userId, isEqualTo(record::getUserId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.625+08:00", comments="Source Table: sys_user")
    default int updateByPrimaryKeySelective(User record) {
        return update(c ->
            c.set(deptId).equalToWhenPresent(record::getDeptId)
            .set(loginName).equalToWhenPresent(record::getLoginName)
            .set(userName).equalToWhenPresent(record::getUserName)
            .set(userType).equalToWhenPresent(record::getUserType)
            .set(email).equalToWhenPresent(record::getEmail)
            .set(phonenumber).equalToWhenPresent(record::getPhonenumber)
            .set(sex).equalToWhenPresent(record::getSex)
            .set(avatar).equalToWhenPresent(record::getAvatar)
            .set(password).equalToWhenPresent(record::getPassword)
            .set(salt).equalToWhenPresent(record::getSalt)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(deleted).equalToWhenPresent(record::getDeleted)
            .set(loginIp).equalToWhenPresent(record::getLoginIp)
            .set(loginDate).equalToWhenPresent(record::getLoginDate)
            .set(createBy).equalToWhenPresent(record::getCreateBy)
            .set(createTime).equalToWhenPresent(record::getCreateTime)
            .set(updateBy).equalToWhenPresent(record::getUpdateBy)
            .set(updateTime).equalToWhenPresent(record::getUpdateTime)
            .set(remark).equalToWhenPresent(record::getRemark)
            .where(userId, isEqualTo(record::getUserId))
        );
    }
}